/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 direction.cpp

	$Header: /heroes4/direction.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "direction.h"

#include <cassert>

#include "map_point.h"
#include "math_constants.h"

// ----------------------------------------------------------------------
// Unnamed namespace
// ----------------------------------------------------------------------

namespace
{

	// ----------------------------------------------------------------------
	// t_direction_properties struct
	// ----------------------------------------------------------------------

	struct t_direction_properties
	{
		std::string		name;
		t_map_point_2d	offset;

		t_direction_properties( std::string const & new_name, t_map_point_2d const & new_offset );
	};

	inline t_direction_properties::t_direction_properties( std::string const & new_name, t_map_point_2d const & new_offset )
		:	name( new_name ),
			offset( new_offset )
	{
	}

	// ----------------------------------------------------------------------
	// ----------------------------------------------------------------------
	inline t_direction_properties const & get_direction_properties( t_direction direction )
	{
		assert( direction >= 0 && direction < k_direction_count );

		static t_direction_properties const k_direction_properties_array[ k_direction_count ] =
		{
			t_direction_properties( "northeast",	t_map_point_2d( -1,  0 ) ),
			t_direction_properties( "east",			t_map_point_2d( -1,  1 ) ),
			t_direction_properties( "southeast",	t_map_point_2d(  0,	 1 ) ),
			t_direction_properties( "south",		t_map_point_2d(  1,  1 ) ),
			t_direction_properties( "southwest",	t_map_point_2d(  1,  0 ) ),
			t_direction_properties( "west",			t_map_point_2d(  1, -1 ) ),
			t_direction_properties( "northwest",	t_map_point_2d(  0, -1 ) ),
			t_direction_properties( "north",		t_map_point_2d( -1, -1 ) ),
		};

		return k_direction_properties_array[ direction ];
	}

} // Unnamed namespace

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
std::string const & get_direction_name( t_direction direction )
{
	return get_direction_properties( direction ).name;
}

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
t_map_point_2d const & get_direction_offset( t_direction direction )
{
	return get_direction_properties( direction ).offset;
}

